﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Pantry.DataAccess;
using Pantry.Business;
using Pantry.Commons;
using Pantry.Entity;

namespace Pantry.UnitTest
{
    [TestFixture]
    public class TestProgramBus
    {
        private Program program;
        private Program programNew;
        private Program programNull = null;
        private const string ConnectionString = "Server=10.16.102.126;Database=Pantry_MockProject;Integrated Security=True;";
        private ProgramBus programBus;
        private ProgramDao programDao;

        

        [SetUp]
        public void Init()
        {

            programDao = new ProgramDao(new SqlConnection(ConnectionString));
            programBus = new ProgramBus(ConnectionString);
            program = new Program
            {
                ContactId = 1,
                Description = "Do con bo",
                IsActive = true,
                ProgramId = 2,
                ProgramName = "Heo Map",
                OrganizationId = 1
            };
            programNew = new Program
            {
                ContactId = 1,
                Description = "Do con bo",
                IsActive = true,
                ProgramId = 2,
                ProgramName = "New programe",
                OrganizationId = 1
            };
        }

        #region Insert Method()
        [Test]
        public void TestInsertProgram()
        {
            int expected = -1;
            int actual;
            actual = programBus.Insert(program);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void TestInsertProgramNull()
        {
            const int expected = 0;
            var actual = programBus.Insert(programNull);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void TestInsertUpdateNew()
        {
            const int expected = 0;
            var actual = programBus.Update(programNew);
            Assert.AreEqual(expected, actual);
        }
        #endregion

        #region Update Method
        [Test]
        public void TestUpdateProgram()
        {
            var expected = programDao.Update(program);
            var actual = programBus.Update(program);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void TestUpdateNull()
        {
            const int expected = 0;
            var actual = programBus.Update(programNull);
            Assert.AreEqual(expected, actual);
        }
        #endregion

        #region ChangeActiveProgram
        public void TestChangeActiveProgramNull()
        {
            const int expected = 0;
            var actual = programBus.ChangeIsActive("Program","IsActive","True","ProgramId",1);
            Assert.AreEqual(expected, actual);
        }

        #endregion

    }
    
}
